import { LevelConfig } from '../types/game';

// 关卡配置数据
export const levelConfigs: Record<string, LevelConfig> = {
  'campaign_1_1': {
    id: 'campaign_1_1',
    name: '巨鹿初战',
    mode: 'campaign',
    boardLayout: [
      [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
      [0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
      [0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
      [1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
      [1, 1, 1, 1, 0, 0, 1, 1, 1, 1],
      [1, 1, 1, 1, 0, 0, 1, 1, 1, 1],
      [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
      [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
      [0, 0, 0, 1, 1, 1, 0, 0, 0, 0]
    ],
    enemyPath: [
      { x: 0, y: 4 }, { x: 1, y: 4 }, { x: 2, y: 4 },
      { x: 3, y: 4 }, { x: 3, y: 3 }, { x: 3, y: 2 },
      { x: 4, y: 2 }, { x: 5, y: 2 }, { x: 6, y: 2 },
      { x: 6, y: 3 }, { x: 6, y: 4 }, { x: 7, y: 4 },
      { x: 8, y: 4 }, { x: 9, y: 4 }
    ],
    waves: [
      {
        enemies: [
          { type: 'infantry', count: 5, interval: 1000 }
        ],
        delay: 3000
      },
      {
        enemies: [
          { type: 'infantry', count: 3, interval: 800 },
          { type: 'cavalry', count: 2, interval: 1500 }
        ],
        delay: 5000
      },
      {
        enemies: [
          { type: 'infantry', count: 4, interval: 600 },
          { type: 'shieldBearer', count: 2, interval: 2000 }
        ],
        delay: 8000
      },
      {
        enemies: [
          { type: 'cavalry', count: 3, interval: 1000 },
          { type: 'siegeEngine', count: 1, interval: 3000 }
        ],
        delay: 10000
      },
      {
        enemies: [
          { type: 'eliteGeneral', count: 1, interval: 5000 },
          { type: 'infantry', count: 6, interval: 500 }
        ],
        delay: 12000
      }
    ],
    initialChessSpirit: 150,
    allowedUnits: ['soldier', 'cannon', 'chariot'],
    playerHealth: 20
  },

  'campaign_1_2': {
    id: 'campaign_1_2',
    name: '垓下围城',
    mode: 'campaign',
    boardLayout: [
      [1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
      [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
      [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
      [1, 1, 1, 0, 0, 0, 0, 1, 1, 1],
      [1, 1, 1, 0, 1, 1, 0, 1, 1, 1],
      [1, 1, 1, 0, 1, 1, 0, 1, 1, 1],
      [1, 1, 1, 0, 0, 0, 0, 1, 1, 1],
      [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
      [1, 1, 1, 1, 1, 1, 1, 1, 1, 0]
    ],
    enemyPath: [
      { x: 0, y: 0 }, { x: 1, y: 0 }, { x: 2, y: 0 },
      { x: 3, y: 0 }, { x: 4, y: 0 }, { x: 5, y: 0 },
      { x: 6, y: 0 }, { x: 7, y: 0 }, { x: 8, y: 0 },
      { x: 8, y: 1 }, { x: 8, y: 2 }, { x: 7, y: 2 },
      { x: 7, y: 3 }, { x: 7, y: 4 }, { x: 7, y: 5 },
      { x: 7, y: 6 }, { x: 8, y: 6 }, { x: 8, y: 7 },
      { x: 8, y: 8 }, { x: 9, y: 8 }
    ],
    waves: [
      {
        enemies: [
          { type: 'infantry', count: 8, interval: 800 }
        ],
        delay: 2000
      },
      {
        enemies: [
          { type: 'cavalry', count: 4, interval: 1200 },
          { type: 'shieldBearer', count: 2, interval: 2000 }
        ],
        delay: 6000
      },
      {
        enemies: [
          { type: 'siegeEngine', count: 2, interval: 3000 },
          { type: 'infantry', count: 6, interval: 600 }
        ],
        delay: 8000
      },
      {
        enemies: [
          { type: 'eliteGeneral', count: 1, interval: 4000 },
          { type: 'cavalry', count: 5, interval: 1000 }
        ],
        delay: 10000
      }
    ],
    initialChessSpirit: 200,
    allowedUnits: ['soldier', 'cannon', 'horse', 'chariot'],
    playerHealth: 25
  },

  'endless_1': {
    id: 'endless_1',
    name: '无尽征战',
    mode: 'endless',
    boardLayout: [
      [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
      [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
      [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
      [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
      [0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
      [0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
      [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
      [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
      [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
    ],
    enemyPath: [
      { x: 0, y: 4 }, { x: 1, y: 4 }, { x: 2, y: 4 },
      { x: 3, y: 4 }, { x: 4, y: 4 }, { x: 5, y: 4 },
      { x: 6, y: 4 }, { x: 7, y: 4 }, { x: 8, y: 4 },
      { x: 9, y: 4 }
    ],
    waves: [], // 无尽模式动态生成波次
    initialChessSpirit: 100,
    allowedUnits: ['soldier', 'cannon', 'horse', 'chariot', 'advisor', 'minister', 'general'],
    playerHealth: 30
  },

  'puzzle_1': {
    id: 'puzzle_1',
    name: '智谋考验',
    mode: 'puzzle',
    boardLayout: [
      [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
      [0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
      [0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
      [1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
      [1, 1, 1, 1, 0, 0, 1, 1, 1, 1],
      [1, 1, 1, 1, 0, 0, 1, 1, 1, 1],
      [0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
      [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
      [0, 0, 0, 1, 1, 1, 0, 0, 0, 0]
    ],
    enemyPath: [
      { x: 0, y: 4 }, { x: 1, y: 4 }, { x: 2, y: 4 },
      { x: 3, y: 4 }, { x: 3, y: 3 }, { x: 3, y: 2 },
      { x: 4, y: 2 }, { x: 5, y: 2 }, { x: 6, y: 2 },
      { x: 6, y: 3 }, { x: 6, y: 4 }, { x: 7, y: 4 },
      { x: 8, y: 4 }, { x: 9, y: 4 }
    ],
    waves: [
      {
        enemies: [
          { type: 'eliteGeneral', count: 1, interval: 2000 },
          { type: 'shieldBearer', count: 3, interval: 1500 }
        ],
        delay: 1000
      }
    ],
    initialChessSpirit: 250, // 解谜模式给予充足资源
    allowedUnits: ['cannon', 'horse'], // 限制可用单位
    playerHealth: 10 // 但生命值较低，需要精确布阵
  }
};

// 获取关卡配置
export function getLevelConfig(levelId: string): LevelConfig | null {
  return levelConfigs[levelId] || null;
}

// 获取所有关卡ID
export function getAllLevelIds(): string[] {
  return Object.keys(levelConfigs);
}

// 根据模式获取关卡
export function getLevelsByMode(mode: 'campaign' | 'endless' | 'puzzle'): LevelConfig[] {
  return Object.values(levelConfigs).filter(level => level.mode === mode);
}